package pers.jason.wppm.edge.web.web.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.jason.wppm.auth.api.entity.User;
import pers.jason.wppm.auth.api.UserApi;
import pers.jason.wppm.auth.api.support.RandomNickName;
import pers.jason.wppm.edge.web.web.service.UserService;

/**
 * @ClassName: UserServiceImpl
 * @Author: JZH
 * @Date: 2018/12/2 21:44
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserApi userApi;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public User findOrCreateUserByMobile(String mobile) {
        User user = userApi.getUserByLoginName("_MOBILE", mobile);
        if(null == user) {
            user = new User();
            user.setUserName(RandomNickName.getRandomJianHan(4));
            user.setMobile(mobile);
            user.setLoginName("111111");
            user.setPassword("111111");
            user = userApi.registWithMobile(user);
            logger.info("新用户：" + user);
        }
        return user;
    }
}
